package cn.kgc.crowdfundingadminspringboot.service;

import cn.kgc.crowdfundingadminspringboot.mapper.CertMapper;
import cn.kgc.crowdfundingadminspringboot.pojo.Cert;
import cn.kgc.crowdfundingadminspringboot.pojo.CertExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class CertServiceImpl implements CertService{
    @Resource
    CertMapper certMapper;

    /**
     * 显示数据加分页和模糊查询
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    public PageInfo<Cert> queryForKeywordSearch(Integer pageNum, Integer pageSize, String keyword) {
        //startPage(从某页开始，一页显示几行)
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy("id desc");
        PageInfo<Cert> pageInfo=null;
        if (keyword!=null&&keyword.length()>0){
            CertExample example=new CertExample();
            CertExample.Criteria criteria = example.createCriteria();
            criteria.andNameLike("%"+keyword+"%");
            List<Cert> list=certMapper.selectByExample(example);
            pageInfo=new PageInfo<>(list);
        }else{
            List<Cert> list=certMapper.selectByExample(null);
            pageInfo=new PageInfo<>(list);
        }
        return pageInfo;
    }

    /**
     * 删除数据
     * @param adminIdList
     */
    @Override
    public void batchRemove(List<Integer> adminIdList) {
        CertExample example = new CertExample();
        CertExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(adminIdList);
        certMapper.deleteByExample(example);
    }

    @Override
    public List<Cert> selectById(List<Integer> adminIdList) {
        CertExample example = new CertExample();
        CertExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(adminIdList);
        return certMapper.selectByExample(example);
    }
}
